﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LP580.CG;

public partial class Manage_UserAccountOperate : System.Web.UI.Page
{
    private string act = Utils.RQ_str("act").ToLower();
    private int id = Utils.RQ_int("id");
    int upid = Utils.RQ_int("upid");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
            bindData();
        bindContrl();
    }

    private void bindContrl()
    {

    }

    private void bindData()
    {
        if (act == "edit")
        {
            ltMgTitle.Text = "修改用户信息";
            ltPathTitle.Text = "[修改用户信息]";
            ltOperTitle.Text = "修改用户信息";
            clsUserAccount cls = new clsUserAccount(id);
            tbxUserName.Text = cls.UserName;
            tbxUserMail.Text = cls.UserMail;
            tbxUserPass.Text = cls.UserPass;
            tbxExpireDate.Text = cls.ExpireDate.ToString("yyyy-MM-dd");
            UserDisable.Checked = cls.UserDisable;
            UserType.SelectedValue = cls.MemberType.ToString();
            //tbxUserAccountCode.Text = cls.UserCode;
            btnSave.Text = " 修 改 ";
            tbxUserName.ReadOnly = true;
            lkUserCompany.Visible = true;
            lkUserCompany.NavigateUrl = "../CG/UserCompanyInfoOperate.aspx?act=edit&id=" + id;
            lkLoginWithThis.Visible = true;
            lkLoginWithThis.NavigateUrl = "../User/UserUtils.aspx?act=login&id=" + id;
        }
        else
        {
            ltMgTitle.Text = "添加用户信息";
            ltPathTitle.Text = "[添加用户信息]";
            ltOperTitle.Text = "添加用户信息";
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string name = tbxUserName.Text.Trim();
        string pass = tbxUserPass.Text.Trim();
        if (name == "")
        {
            Utils.WrAlertGoBack("用户名不可为空！");
        }
        clsUserAccount cls = new clsUserAccount(id);
        cls.UserName = name;
        if (pass != "")
        {
            cls.UserPass = pass;
        }
        DateTime dtTmp = new DateTime(1900, 1, 1);
        if (!DateTime.TryParse(tbxExpireDate.Text, out dtTmp))
            dtTmp = new DateTime(1900, 1, 1);
        cls.ExpireDate = dtTmp;
        cls.UserMail = tbxUserMail.Text.Trim();
        cls.UserDisable = UserDisable.Checked;
        cls.MemberType = Convert.ToInt16(UserType.SelectedValue);
        if (act.ToLower() == "edit")
        {
            clsUserAccount.Update(cls);
        }
        else
        {
            if (!clsUserAccount.ExistUsername(name))
                clsUserAccount.Insert(cls);
        }
        Response.Redirect("UserAccountList.aspx", true);
    }
}